package mine.personal.demo.pratice.algorithm.stimulate;

/**
 * @Author:lhl
 * @CreateTime: 2025-04-15
 * @Description: 模拟算法集合
 * @Version: 1.0
 */
public class Solution {

    /**
     * leetcode -> 删除问号
     * @author: 李鸿麟
     * @date: 2025/4/15
     * @param: s
     * @return: String
     */
    public String modifyString(String s) {
        char[] c = s.toCharArray();
        int n = c.length;
        for (int i = 0; i < n; i++) {
            if (c[i] == '?') {
                for (char j = 'a'; j <= 'z'; j++) {
                    if (((i == 0) || (j != c[i + 1])) && ((i == n) || (j != c[i - 1]))) {
                        c[i] = j;
                        break;
                    }
                }
            }
        }
        return String.valueOf(c); 
    }

    /**
     * leetcode -> 提莫攻击
     * @author: 李鸿麟
     * @date: 2025/4/16
     * @param: timeSeries
     * @param: duration
     * @return: int
     */
    public static int findPoisonedDuration(int[] timeSeries, int duration) {
        int ret = 0;
        int n = timeSeries.length;
        for (int i = 1; i <= n; i++) {
            if (i < n) {
                int pre = timeSeries[i - 1];
                int now = timeSeries[i];
                if (now - pre >= duration) {
                    ret += duration;
                } else {
                    ret += (now - pre);
                }
            }
            else {
                ret += duration;
            }
        }
        return ret;
    }

    public static void main(String[] args) {
        int[] arr = {1, 2};
        System.out.println(findPoisonedDuration(arr, 2));
    }
}
